import SelectUtil from "solar/util/SelectUtil";

export default class AddGoldByHaveAbilityOnPer5sState {

    static config: { [id: string]: number } = {}


    constructor() {
        let triggerHandle = CreateTrigger();
        TriggerRegisterTimerEventPeriodic(triggerHandle, 5.00);
        TriggerAddAction(triggerHandle, this.action);
    }

    action(this: void) {
        SelectUtil.forAllUnits(unit => {
            for (let abilityIdStr in AddGoldByHaveAbilityOnPer5sState.config) {
                if (GetUnitAbilityLevel(unit, FourCC(abilityIdStr)) > 0 && IsUnitAliveBJ(unit)) {
                    let int = AddGoldByHaveAbilityOnPer5sState.config[abilityIdStr];
                    AdjustPlayerStateBJ(int, GetOwningPlayer(unit), PLAYER_STATE_RESOURCE_GOLD);
                    CreateTextTagUnitBJ((" +" + I2S(int)), unit, 0, 10, 100.00, 84.00, 0, 0);
                    SetTextTagVelocityBJ(GetLastCreatedTextTag(), 100.00, 90);
                    SetTextTagPermanent(GetLastCreatedTextTag(), false);
                    SetTextTagLifespan(GetLastCreatedTextTag(), 0.20);
                }
            }
        });
    }


}

